﻿using System;

namespace SharpTrainer
{
  public delegate bool CompareOp(object lhs, object rhs);
  
  public class DelegateAlgorithm
  {
    public static bool RhsIsGreater(object lhs, object rhs)
    {
        MyEmployee empLhs = (MyEmployee)lhs;
        MyEmployee empRhs = (MyEmployee)rhs;
      return (empRhs.Salary > empLhs.Salary) ? true : false;
    }

    public static bool RhsIsLess(object lhs, object rhs)
    {
        MyEmployee empLhs = (MyEmployee)lhs;
        MyEmployee empRhs = (MyEmployee)rhs;
      return (empRhs.Salary < empLhs.Salary) ? true : false;
    }

    public static void BubbleSorter(object[] sortArray, CompareOp gtMethod)
    {
      for (int i = 0; i < sortArray.Length; i++)
      {
        for (int j = i + 1; j < sortArray.Length; j++)
        {
          if (gtMethod(sortArray[j], sortArray[i]))
          {
            object temp = sortArray[i];
            sortArray[i] = sortArray[j];
            sortArray[j] = temp;
          }
        }
      }
    }

  }
}
